package com.sc.common.service;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.function.Function;

abstract public class AbstractBaseService<M extends BaseMapper<E>, E> extends ServiceImpl<M, E> {

    public <O, T> Page<T> pageConversion(Page<O> page, Function<O, T> build){
        Page<T> conversionPage = new Page<>(page.getCurrent(), page.getSize());
        conversionPage.setRecords(page.getRecords().stream().map(build).toList());
        conversionPage.setTotal(page.getTotal());
        return conversionPage;
    }
}
